package org.frog.sgs.server.game;

import java.util.ArrayList;
import java.util.List;

import org.frog.sgs.event.SgsEvent;

/**
 * 整个游戏进程中，需要处理的事件按顺序加入。处理顺序：先添加先处理
 * 
 * @author duanxiangqi
 * @date 2012-10-29
 */
public class ServerEventManager {

	private ServerInstance instance;

	private List<SgsEvent> events = new ArrayList<SgsEvent>();

	/** 整个游戏进程中，需要处理的事件按顺序加入。处理顺序：先添加先处理 */
	public void addEvent(SgsEvent event) {
		events.add(0, event);
		System.err.println("添加事件" + event.getViewName());
	}

	public SgsEvent getLast() {
		if (events.isEmpty()) {
			return null;
		}
		SgsEvent event = events.get(events.size() - 1);
		return event;
	}

	public SgsEvent removeLast() {
		if (events.isEmpty()) {
			return null;
		}
		SgsEvent event = events.remove(events.size() - 1);
		System.err.println("删除事件" + event.getViewName());
		return event;
	}

	public ServerInstance getInstance() {
		return instance;
	}

	public void setInstance(ServerInstance instance) {
		this.instance = instance;
	}

	public List<SgsEvent> getEvents() {
		for (int i = 0; i < events.size(); i++) {
			System.err.println("当前所有事件(" + i + ")：" + events.get(i).getViewName());
		}
		return events;
	}
}
